package com.android.clinic.app.ui.personal.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;

import com.android.clinic.app.R;
import com.android.clinic.app.glide.ImageLoaderUtils;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;

/**
 * 单张图片查看器
 * Created by cheng on 2018/7/17.
 */
public class ImageDetailFragment extends Fragment {

    private String mImageUrl;
    private SubsamplingScaleImageView mImageView;
    private ProgressBar progressBar;

    public static ImageDetailFragment newInstance(String imageUrl) {
        final ImageDetailFragment f = new ImageDetailFragment();
        final Bundle args = new Bundle();
        args.putString("url", imageUrl);
        f.setArguments(args);
        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mImageUrl = getArguments() != null ? getArguments().getString("url")
                : null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View v = inflater.inflate(R.layout.fragment_image_detail,
                container, false);
        mImageView = (SubsamplingScaleImageView) v.findViewById(R.id.image);
        progressBar = (ProgressBar) v.findViewById(R.id.progressbar);
        return v;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ImageLoaderUtils.getInstance().loadBigImage(mImageUrl, mImageView, progressBar);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}
